package com.atguigu.tingshu.account.api;

import com.atguigu.tingshu.account.service.RechargeInfoService;
import com.atguigu.tingshu.common.login.EnableLoginAuth;
import com.atguigu.tingshu.common.result.Result;
import com.atguigu.tingshu.model.account.RechargeInfo;
import com.atguigu.tingshu.vo.account.RechargeInfoVo;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

@Tag(name = "充值管理")
@RestController
@RequestMapping("api/account/rechargeInfo")
@SuppressWarnings({"unchecked", "rawtypes"})
public class RechargeInfoApiController {

    @Autowired
    private RechargeInfoService rechargeInfoService;
    @EnableLoginAuth
    @PostMapping("/submitRecharge")
    public Result<Map<String, Object>> submitRecharge(@RequestBody RechargeInfoVo rechargeInfoVo) {
        Map<String, Object> objectMap = this.rechargeInfoService.submitRecharge(rechargeInfoVo);
        return Result.ok(objectMap);
    }

    @GetMapping("/getRechargeInfo/{orderNo}")
    public Result<RechargeInfo> getRechargeInfo(@PathVariable String orderNo){
        RechargeInfo rechargeInfo = this.rechargeInfoService.getOne(new LambdaQueryWrapper<RechargeInfo>()
                .eq(RechargeInfo::getOrderNo, orderNo));
        return Result.ok(rechargeInfo);
    }

}

